from django.db import models

class Account(models.Model):
    account_number = models.CharField(max_length=20, unique=True)  # 账户号码，唯一
    balance = models.DecimalField(max_digits=10, decimal_places=2)  # 账户余额，最多10位数字，2位小数

    def deposit(self, amount):
        """存入指定金额到账户中"""
        if amount <= 0:
            raise ValueError("存入金额必须大于0")
        self.balance += amount  # 增加余额
        self.save()  # 保存账户信息

    def withdraw(self, amount):
        """从账户中取出指定金额"""
        if amount <= 0:
            raise ValueError("取出金额必须大于0")
        if amount > self.balance:
            raise ValueError("余额不足")  # 如果余额不足，抛出异常
        self.balance -= amount  # 减少余额
        self.save()  # 保存账户信息

    def get_balance(self):
        """返回账户余额"""
        return self.balance
